package cn.xspace.module.other.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xspace.android.xafcommon.been.Equipment;

import java.util.ArrayList;
import java.util.List;

import cn.xspace.library.util.ViewHolder;
import cn.xspace.module.other.R;

//import cn.xspace.library.util.ViewHolder;

/**
 * Created by liuchen on 2016/12/13.
 */

public class RecentLoginAdapter extends BaseAdapter {
    private List<Equipment> mDataList = new ArrayList<>();

    private Context mContext;

    public RecentLoginAdapter(Context mContext, List<Equipment> eqlist) {
        this.mContext = mContext;
        this.mDataList = eqlist;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Equipment getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mDataList.get(position).hashCode();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Equipment equipment = getItem(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.listitem_recent_login, parent, false);
        }
        if (equipment.manufacturer.contains("iPhone")) {
            ((TextView) ViewHolder.get(convertView, R.id.txt_device_platform)).setText("iPhone");
        } else {
            ((TextView) ViewHolder.get(convertView, R.id.txt_device_platform)).setText("android");
        }
        ((TextView) ViewHolder.get(convertView, R.id.txt_time)).setText(equipment.imei);
        ((TextView) ViewHolder.get(convertView, R.id.txt_device_type)).setText(equipment.manufacturer);
        return convertView;
    }

}
